
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_background/flutter_background.dart';
import 'package:flutter_scaffold_plugin/config/config.dart';
import 'package:flutter_scaffold_plugin/routes/app_pages.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';

class FlutterScaffoldPlugin {
  static const MethodChannel _channel =
      const MethodChannel('flutter_scaffold_plugin');

  static Future<String> get platformVersion async {
    final String version = await _channel.invokeMethod('getPlatformVersion');
    return version;
  }

  void init(){
    _initConfig();
    _configWebRTC();
  }

  _initConfig() {
    //注册跳转页面路由
    AppPages.configureRoutes();

    /// 配置环境
    Config.env = "";
  }

  _configWebRTC() {
    if (WebRTC.platformIsAndroid) {
      WidgetsFlutterBinding.ensureInitialized();
      _startForegroundService();
    }
  }

  Future<bool> _startForegroundService() async {
    final androidConfig = FlutterBackgroundAndroidConfig(
      notificationTitle: 'Title of the notification',
      notificationText: 'Text of the notification',
      notificationImportance: AndroidNotificationImportance.Default,
      notificationIcon: AndroidResource(
          name: 'background_icon',
          defType: 'drawable'), // Default is ic_launcher from folder mipmap
    );
    return FlutterBackground.initialize(androidConfig: androidConfig);
  }
}
